﻿using System;
using System.Text;

namespace Ayatta.Contract.Domain
{

    #region AccountPayment

    /// <summary>
    /// 支付
    /// </summary>
    public class AccountPayment : BaseEntity<string>
    {
        /// <summary>
        /// 支付平台订单号（不同支付平台需要的格式不一样）
        /// </summary>
        public string PayNo { get; set; }

        /// <summary>
        /// 用户Id
        /// </summary>
        /// <value></value>
        public int UserId { get; set; }

        /// <summary>
        /// 支付类型 0为订单支付 1为充值
        /// </summary>
        /// <value></value>
        public PaymentCategory Category { get; set; }

        /// <summary>
        /// 当Category=1时 0账户充值 1拍币充值 2游戏充值
        /// </summary>
        /// <value></value>
        public byte SubCategory { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string ForeignKey { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public decimal Amount { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public decimal Balance { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public PaymentMethod Method { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public int EBankId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public Platform PlatformId { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string Gateway { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public BankCard BankCard { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string BankName { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string CardNo { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string CardPwd { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public decimal CardAmount { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string IpAddress { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string ExternalNo { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public int Flag { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value></value>
        public string Extra { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <value>((0))</value>
        public bool Status { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public DateTime? PaidOn { get; set; }

        /// <summary>
        /// 生成22位随机字符做为Id
        /// </summary>
        /// <returns></returns>
        public static string NewId()
        {
            const string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var time = DateTime.Now;
            var sb = new StringBuilder()
                .Append(time.ToString("yyMMddHHmm"));

            var b = new byte[4];
            new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
            var r = new Random(BitConverter.ToInt32(b, 0));

            for (var i = 0; i < 12; i++)
            {
                sb.Append(str.Substring(r.Next(0, str.Length - 1), 1));
            }
            return sb.ToString();

        }

        /// <summary>
        /// 生成PayNo
        /// </summary>
        /// <returns></returns>
        public static string NewPayNo()
        {
            const string str = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

            var time = DateTime.Now;
            var sb = new StringBuilder()
                .Append(time.ToString("yyMMddHHmm"));

            var b = new byte[4];
            new System.Security.Cryptography.RNGCryptoServiceProvider().GetBytes(b);
            var r = new Random(BitConverter.ToInt32(b, 0));

            for (var i = 0; i < 6; i++)
            {
                sb.Append(str.Substring(r.Next(0, str.Length - 1), 1));
            }
            return sb.ToString();

        }
    }

    #endregion

}